home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BTCLASS.ZIP / BTCLASS@.EXE / BTBUFF.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-21  |  3.7 KB  |  91 lines

  1. /*//////////////////////////////////////////////////////////////////////////
  2. ///            ___                                                       ///
  3. ///          /_____\                                                     ///
  4. ///         |       |               Copyright (c) 1991, 1992             ///
  5. ///         |   R   |                                                    ///
  6. ///     ----|_______|----                     by                         ///
  7. ///   /------/ | | \------\                                              ///
  8. ///  |       | | | |       |      --  Object Resource Corp.  --          ///
  9. ///  |   O   | | | |   C   |                                             ///
  10. ///  |       |/   \|       |          4323 Brown Suite 249               ///
  11. ///   -------       -------            Dallas,  TX  75219                ///
  12. ///   Object Resource Corp.                                              ///
  13. ///                                      (214) 528-2745                  ///
  14. ///                                                                      ///
  15. ///                                    All Rights Reserved.              ///
  16. ///                                                                      ///
  17. //////////////////////////////////////////////////////////////////////////*/
  18.  
  19. #if !defined(BTBUFF_HPP)
  20. #define BTBUFF_HPP    1
  21.  
  22. //////////////////////////// CLASS BTBUFF /////////////////////////
  23.  
  24. class BT_Buff
  25.     {
  26.     friend class BT_DataSet;
  27.     friend class BT_Key;
  28.         //   This class is handy to use as a base class for specific
  29.         //   record structures...or, if using variable length records,
  30.         //   you may want to have a BT_Buff long enough for the maximum
  31.         //   length record (cf. BT_DataSet class)
  32.  
  33.     protected:
  34.         void *buffer;        // pointer to actual buffer
  35.         int   bufflen;        // length of buffer in bytes
  36.         int   datalen;        // length of DATA in buffer
  37.  
  38.         void *BuffAddr()   { return buffer; }
  39.         int  *LenAddr()    { return &datalen; }
  40.         void  SetDataMax() { datalen = bufflen; }
  41.  
  42.     public:
  43.                 // CONSTRUCTORS
  44.                 //   Start with no buffer allocated
  45.         BT_Buff()    { buffer=0; datalen=bufflen=0; }
  46.                 //   Allocate buffer of given length
  47.         BT_Buff(int Length);
  48.                 //   Use buffer provided by the user.  NOTE: The BT_Buff
  49.                 //   object now owns the memory...it will be freed when
  50.                 //   the BT_Buff object destructor is called.
  51.         BT_Buff( void *buff, int Length )
  52.             {
  53.             buffer = buff;
  54.             datalen = bufflen = Length; // assumption!
  55.             }
  56.  
  57.         // DESTRUCTOR
  58.         ~BT_Buff()    { delete buffer; }
  59.  
  60.         //   Copy data into existing buffer.  No data will be
  61.                 //   copied past the buffer's end even if 'DLth' is
  62.                 //   longer than the buffer.
  63.         int SetBufferData(const void *Data, int DLth);
  64.  
  65.         //   Fills buffer with data from user buffer.  'bufflen'
  66.                 //   bytes are copied from 'Data' to object's buffer
  67.         void FillBuffer(const void *Data);
  68.  
  69.         //   Copy data from buffer to user's buffer...using the
  70.                 //   object's datalen for the number of bytes to copy,
  71.                 //   but no more that 'Lth'
  72.         int GetBufferData(void *UserBuff,int Lth);
  73.  
  74.         //   Set object's buffer to a new length.  No data is
  75.                 //   retained in the new buffer.
  76.         virtual int SetBuffer(int Length);
  77.  
  78.         //   Sets object buffer to 'Data' and bufflen and datalen to
  79.                 //   'DLth'.  Destructor will free the buffer!!
  80.         virtual int SetBuffer(void *Data, int DLth);
  81.  
  82.         //   Get Length of Data in Buffer
  83.         int DataLen() { return datalen; }
  84.  
  85.         //   Get Length of Object's Buffer
  86.         int BuffLen() { return bufflen; }
  87.     };
  88.  
  89.  
  90. #endif
  91.